From 94157ec199cd78cd70899ce7f5d4bc93026dda58 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Wed, 25 Mar 2009 19:02:35 +0000 Subject: [PATCH] Handle variadic macros in a portable way Apply patch from Gary V. Vaughan that adds configure time checks for variadic macros and adapts the definitions of such macros in-code accordingly so that babl can be compiled on more platforms. svn path=/trunk/; revision=400 --- ChangeLog | 10 +++++++ acinclude.m4 | 62 ++++++++++++++++++++++++++++++++++++++++++++ babl/babl-internal.h | 42 ++++++++++++++++++++++++++++-- configure.ac | 2 ++ 4 files changed, 114 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7aae42c..b8d3840 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2009-03-25 Martin Nordholts + Apply patch from Gary V. Vaughan that adds configure time checks + for variadic macros and adapts the definitions of such macros + in-code accordingly so that babl can be compiled on more + platforms. + + * acinclude.m4 + * babl/babl-internal.h + * configure.ac + +2009-03-25 Martin Nordholts * babl/babl-fish.c: Patch from Gary V. Vaughan. Some vendor compilers can't compile non-constant elements of compound struct initializers diff --git a/acinclude.m4 b/acinclude.m4 index 3fad630..4ea58bd 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -18,3 +18,65 @@ AC_DEFUN([BABL_DETECT_CFLAGS], fi done ]) + + +# BABL_VARIADIC_MACROS +# -------------------- +# check for flavours of variadic macros +AC_DEFUN([BABL_VARIADIC_MACROS], +[AC_BEFORE([$0], [AC_PROG_CXX]) +AC_REQUIRE([AC_PROG_CPP]) +AC_CACHE_CHECK([for GNUC variadic macros], + [babl_cv_prog_gnuc_variadic_macros], + [# gcc-2.95.x supports both gnu style and ISO varargs, but if -ansi + # is passed ISO vararg support is turned off, and there is no work + # around to turn it on, so we unconditionally turn it off. + { echo '#if __GNUC__ == 2 && __GNUC_MINOR__ == 95' + echo ' yes ' + echo '#endif'; } > conftest.c + if ${CPP} conftest.c | grep yes > /dev/null; then + babl_cv_prog_c_variadic_macros=no + babl_cv_prog_cxx_variadic_macros=no + fi + AC_TRY_COMPILE([],[int a(int p1, int p2, int p3); +#define call_a(params...) a(1,params) +call_a(2,3); + ], + babl_cv_prog_gnuc_variadic_macros=yes, + babl_cv_prog_gnuc_variadic_macros=no) +]) +if test x$babl_cv_prog_gnuc_variadic_macros = xyes; then + AC_DEFINE(BABL_GNUC_VARIADIC_MACROS, 1, [Define if the C pre-processor supports GNU style variadic macros]) +fi + +AC_CACHE_CHECK([for ISO C99 variadic macros in C], + [babl_cv_prog_c_variadic_macros], + [AC_TRY_COMPILE([],[int a(int p1, int p2, int p3); +#define call_a(...) a(1,__VA_ARGS__) +call_a(2,3); + ], + babl_cv_prog_c_variadic_macros=yes, + babl_cv_prog_c_variadic_macros=no) +]) +if test x$babl_cv_prog_c_variadic_macros = xyes ; then + AC_DEFINE(BABL_ISO_VARIADIC_MACROS, 1, [Define if the C pre-processor supports variadic macros]) +fi + +AC_PROVIDE_IFELSE([AC_PROG_CXX], + [AC_CACHE_CHECK([for ISO C99 variadic macros in C++], + [babl_cv_prog_cxx_variadic_macros], + [AC_LANG_PUSH(C++) + AC_TRY_COMPILE([],[int a(int p1, int p2, int p3); +#define call_a(...) a(1,__VA_ARGS__) +call_a(2,3); + ], + babl_cv_prog_cxx_variadic_macros=yes, + babl_cv_prog_cxx_variadic_macros=no) + AC_LANG_POP])], + [# No C++ compiler + babl_cv_prog_cxx_variadic_macros=no]) +if test x$babl_cv_prog_cxx_variadic_macros = xyes ; then + AC_DEFINE(BABL_ISO_CXX_VARIADIC_MACROS, 1, [Define if the C++ pre-processor supports variadic macros]) +fi +]) + diff --git a/babl/babl-internal.h b/babl/babl-internal.h index a43bb7b..a83e506 100644 --- a/babl/babl-internal.h +++ b/babl/babl-internal.h @@ -162,19 +162,57 @@ real_babl_log (const char *file, hack_hack (); } +#if defined(__cplusplus) && defined(BABL_ISO_CXX_VARIADIC_MACROS) +# define BABL_ISO_VARIADIC_MACROS 1 +#endif + +#if defined(BABL_ISO_VARIADIC_MACROS) + +#define babl_log(...) \ + real_babl_log(__FILE__, __LINE__, __func__, __VA_ARGS__) + +#define babl_fatal(...) do{ \ + real_babl_log(__FILE__, __LINE__, __func__, __VA_ARGS__); \ + babl_die();} \ +while(0) + +#elif defined(BABL_GNUC_VARIADIC_MACROS) + #define babl_log(args...) \ real_babl_log(__FILE__, __LINE__, __func__, args) #define babl_fatal(args...) do{ \ - real_babl_log(__FILE__, __LINE__, __func__, args);\ + real_babl_log(__FILE__, __LINE__, __func__, args); \ babl_die();} \ while(0) +#else + +static inline void +babl_log (const char *format, ...) +{ + va_list args; + va_start (args, format); + real_babl_log (__FILE__, __LINE__, __func__, format, args); + va_end (args); +} +static inline void +babl_fatal (const char *format, ...) +{ + va_list args; + va_start (args, format); + real_babl_log (__FILE__, __LINE__, __func__, format, args); + va_end (args); + babl_die(); +} + +#endif + #define babl_assert(expr) do{ \ if(!(expr)) \ { \ - babl_fatal("Eeeeek! Assertion failed: `" #expr "`"); \ + real_babl_log(__FILE__, __LINE__, __func__, "Eeeeek! Assertion failed: `" #expr "`"); \ assert(expr); \ } \ }while(0) diff --git a/configure.ac b/configure.ac index a11306d..7d03255 100644 --- a/configure.ac +++ b/configure.ac @@ -100,6 +100,8 @@ AM_MAINTAINER_MODE AC_STDC_HEADERS AM_SANITY_CHECK +BABL_VARIADIC_MACROS + WEBSITE_HOST=pippin.gimp.org AC_SUBST(WEBSITE_HOST) WEBSITE_LOCATION=public_html/babl/ -- 2.30.2